package com.ih.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.ih.mapper.WorkerMapper;
import com.ih.pojo.Customer;
import com.ih.pojo.Worker;
import com.ih.service.WorkerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class WorkerServiceImpl implements WorkerService {
    @Autowired
    private WorkerMapper workerMapper;

    /**
     * 查询所有用户
     * @return
     */
    @Override
    public List<Worker> queryWorker() {
        return workerMapper.selectList(null);
    }

    /**
     * 模糊查询带分页
     *
     * @param worker
     * @param pageSize
     * @param pageNum
     * @return
     */
    @Override
    public PageInfo<Worker> listWorker(Worker worker, Integer pageSize, Integer pageNum) {
        List<Worker> list = workerMapper.listWorker(worker);

        return new PageInfo<>(list);
    }



    /**
     * 添加送水工
     *
     * @param worker 送水工信息
     * @return 受影响行数，大于0添加成功，否则添加失败
     */
    @Override
    public int saveWorker(Worker worker) {
        return workerMapper.insert(worker);
    }

    /**
     * 根据送水工ID获取对应的送水工信息
     *
     * @param wid 送水工id
     * @return 送水工信息
     */
    @Override
    public Worker getWorkerById(Integer wid) {
        QueryWrapper<Worker> qw=new QueryWrapper<>();
        qw.eq("wid",wid);
        Worker worker = workerMapper.selectOne(qw);
        return worker;
    }

    /**
     * 修改
     *
     * @param worker
     * @return
     */
    @Override
    public Integer updateWorker(Worker worker) {
        QueryWrapper<Worker> qw=new QueryWrapper<>();
        qw.eq("wid",worker.getWid());
        return workerMapper.update(worker,qw);
    }

    /**
     * 调整工资
     * @param wid
     * @param workerSalary
     * @return
     */
    @Override
    public int addSalary(Integer wid, Integer workerSalary) {
        return workerMapper.addSalary(wid,workerSalary);
    }


}
